% Average phase velocity window configuration
% June 2016
% Hamzeh Sadeghisorkhani

%% Average velocity panel
h.panel(4)= uipanel(mainfig,'visible','off','Position',[.235 .15 .74 .8]);
set(h.panel(4),'BackgroundColor',panel_color)



%% Text boxes
%-------------------------------- Existing Dispersion (Reference)
uicontrol(h.panel(4),'Style','text', 'String','Existing Dispersion (Reference)',...
    'HorizontalAlignment','left','Fontweight','bold',...
    'Units','normalized','Position',[.01 .92 .4 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(4),'Style','text', 'String','File format',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .84 .24 .05],...
    'BackgroundColor',panel_color);
uicontrol(h.panel(4),'Style','text', 'String','Delimiter',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.68 .84 .24 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(4),'Style','text', 'String','Rayleigh Wave',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .78 .24 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(4),'Style','text', 'String','Love Wave',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .72 .24 .05],...
    'BackgroundColor',panel_color);




%-------------------------------- Reference Dispersion Calculation
uicontrol(h.panel(4),'Style','text', 'String','Reference Dispersion Calculation',...
    'HorizontalAlignment','left','Fontweight','bold',...
    'Units','normalized','Position',[.01 .6 .4 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(4),'Style','text', 'String','Component',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .52 .2 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(4),'Style','text', 'String','Cmin',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .46 .2 .05],...
    'BackgroundColor',panel_color);
uicontrol(h.panel(4),'Style','text', 'String','Cmax',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.3 .46 .2 .05],...
    'BackgroundColor',panel_color);
uicontrol(h.panel(4),'Style','text', 'String','dC',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.55 .46 .2 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(4),'Style','text', 'String','Norm',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .4 .2 .05],...
    'BackgroundColor',panel_color);

uicontrol(h.panel(4),'Style','text', 'String','Velocity filter',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .34 .2 .05],...
    'BackgroundColor',panel_color);
uicontrol(h.panel(4),'Style','text', 'String','Interval',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.3 .34 .2 .05],...
    'BackgroundColor',panel_color);
uicontrol(h.panel(4),'Style','text', 'String','km/s',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.55 .34 .2 .05],...
    'BackgroundColor',panel_color);


uicontrol(h.panel(4),'Style','text', 'String','T (Periods)',...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.05 .27 .2 .05],...
    'BackgroundColor',panel_color);


%% Editable text 
%-------------------------------- Existing Dispersion (Reference)
h2.ref= uicontrol(h.panel(4),'Style','checkbox', 'String','',...
    'HorizontalAlignment','left','Value',1,...
    'Tag','ref',...
    'Units','normalized','Position',[.42 .935 .1 .04],...
    'BackgroundColor',panel_color,'callback',@checkbox_cbk);

h2.radiobutton(3)= uibuttongroup(h.panel(4),'units','normalized','BackgroundColor',panel_color,...
    'bordertype','none','Position',[.17 .855 .5 .05]);

h2.radio(7) = uicontrol( h2.radiobutton(3), 'Style','Radio','String','.mat',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.1 0 .3 1],'HandleVisibility','off');
h2.radio(8) = uicontrol( h2.radiobutton(3), 'Style','Radio','String','Excel',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.45 0 .3 1],'HandleVisibility','off');
h2.radio(9) = uicontrol( h2.radiobutton(3), 'Style','Radio','String','txt',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.8 0 .3 1],'HandleVisibility','off');

h2.delim= uicontrol(h.panel(4),'Style','popup', ...
    'String',{'tab','space',',','-',';'},'Value',1,...
    'HorizontalAlignment','left','Enable','on',...
    'Units','normalized','Position',[.79 .855 .1 .04],...
    'BackgroundColor','w');

h2.Rayleigh_ave= uicontrol(h.panel(4),'Style','edit', 'String',params.Rayleigh_ave,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.22 .795 .6 .04],...
    'BackgroundColor','w');
h2.Love_ave= uicontrol(h.panel(4),'Style','edit', 'String',params.Love_ave,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.22 .735 .6 .04],...
    'BackgroundColor','w');


h2.icon(3)= uicontrol(h.panel(4),'Style','pushbutton', 'String','',...
    'Cdata',icons.file,'Tag','Rayleigh_file',...
    'Units','normalized','Position',[.83 .795 .06 .04],...
    'callback',@folder_cbk);
h2.icon(4)= uicontrol(h.panel(4),'Style','pushbutton', 'String','',...
    'Cdata',icons.file,'Tag','Love_file',...
    'Units','normalized','Position',[.83 .735 .06 .04],...
    'callback',@folder_cbk);



%--------------------------------- Reference Dispersion Calculation
h2.radiobutton(4)= uibuttongroup(h.panel(4),'units','normalized','BackgroundColor',panel_color,...
    'bordertype','none','Position',[.2 .535 .7 .05]);

h2.radio(10) = uicontrol( h2.radiobutton(4), 'Style','Radio','String','ZZ',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.1 0 .15 1],'HandleVisibility','off');
h2.radio(11) = uicontrol( h2.radiobutton(4), 'Style','Radio','String','ZR',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.25 0 .15 1],'HandleVisibility','off');
h2.radio(12) = uicontrol( h2.radiobutton(4), 'Style','Radio','String','RR',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.4 0 .15 1],'HandleVisibility','off');
h2.radio(13) = uicontrol( h2.radiobutton(4), 'Style','Radio','String','TT',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.55 0 .15 1],'HandleVisibility','off');
h2.radio(17) = uicontrol( h2.radiobutton(4), 'Style','Radio','String','RZ',...
    'BackgroundColor',panel_color, 'units','normalized','position',[.7 0 .15 1],'HandleVisibility','off');

h2.Cmin= uicontrol(h.panel(4),'Style','edit', 'String',params.Cmin,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.12 .475 .1 .04],...
    'BackgroundColor','w');
h2.Cmax= uicontrol(h.panel(4),'Style','edit', 'String',params.Cmax,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.38 .475 .1 .04],...
    'BackgroundColor','w');
h2.dC= uicontrol(h.panel(4),'Style','edit', 'String',params.dC,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.6 .475 .1 .04],...
    'BackgroundColor','w');

h2.norm= uicontrol(h.panel(4),'Style','edit', 'String',params.norm,...
    'HorizontalAlignment','left',...
    'Units','normalized','Position',[.12 .415 .1 .04],...
    'BackgroundColor','w');

h2.vtaper2= uicontrol(h.panel(4),'Style','checkbox', 'String','',...
    'HorizontalAlignment','left','Value',0,...
    'Tag','vtaper2',...
    'Units','normalized','Position',[.24 .355 .04 .04],...
    'BackgroundColor',panel_color,'callback',@checkbox_cbk);
h2.vt_inter2= uicontrol(h.panel(4),'Style','edit', 'String',params.vt_inter2,...
    'HorizontalAlignment','left','Enable','off',...
    'Units','normalized','Position',[.4 .355 .1 .04],...
    'BackgroundColor','w');

h2.periods= uicontrol(h.panel(4),'Style','edit', 'String',params.periods,...
    'HorizontalAlignment','left','Max',2,...
    'Units','normalized','Position',[.18 .12 .1 .2],...
    'BackgroundColor','w');




%% Saving buttons

uicontrol('parent',h.panel(4),'style','pushbutton', 'string','Default',...
    'ToolTipString','Load default setting','Tag','default4',...
    'units','normalized','position',[.1 .03 .18 .07], ...
    'callback',@default_cbk);

uicontrol(h.panel(4),'style','pushbutton', 'string','Latest',...
    'ToolTipString','Load latest setting','Tag','latest4',...
    'units','normalized','position',[.41 .03 .18 .07], ...
    'callback',@latest_cbk);

uicontrol(h.panel(4),'style','pushbutton', 'string','Save',...
    'ToolTipString','Save setting changes','Tag','save4',...
    'units','normalized','position',[.72 .03 .18 .07], ...
    'callback',@save_cbk);



%% Setting values
if strcmp(params.ref,'yes')
    set (h2.ref,'value',1);    
    set(h2.radio(7:9),'Enable','on');
    set(h2.Rayleigh_ave,'Enable','on');        
    set(h2.Love_ave,'Enable','on');
    set(h2.icon(3:4),'Enable','on');
    set(h2.delim,'Enable','on');
elseif strcmp(params.ref,'no')
    set (h2.ref,'value',0);    
    set(h2.radio(7:9),'Enable','off');
    set(h2.Rayleigh_ave,'Enable','off');
    set(h2.Love_ave,'Enable','off');
    set(h2.icon(3:4),'Enable','off');
    set(h2.delim,'Enable','off');
end

set(h2.delim,'Value',params.delim);

if strcmp(params.format,'.mat')
    set (h2.radio(7),'value',1);
    set (h2.radio(8),'value',0);
    set (h2.radio(9),'value',0);    
elseif strcmp(params.format,'Excel')
    set (h2.radio(7),'value',0);
    set (h2.radio(8),'value',1);
    set (h2.radio(9),'value',0);    
elseif strcmp(params.format,'txt')
    set (h2.radio(7),'value',0);
    set (h2.radio(8),'value',0);
    set (h2.radio(9),'value',1);    
    set (h2.delim,'Enable','on');
end


if strcmp(params.component2,'ZZ')
    set (h2.radio(10),'value',1);
    set (h2.radio(11),'value',0);
    set (h2.radio(12),'value',0);
    set (h2.radio(13),'value',0);
    set (h2.radio(17),'value',0);
elseif strcmp(params.component2,'ZR')
    set (h2.radio(10),'value',0);
    set (h2.radio(11),'value',1);
    set (h2.radio(12),'value',0);
    set (h2.radio(13),'value',0);
    set (h2.radio(17),'value',0);
elseif strcmp(params.component2,'RR')
    set (h2.radio(10),'value',0);
    set (h2.radio(11),'value',0);
    set (h2.radio(12),'value',1);
    set (h2.radio(13),'value',0);
    set (h2.radio(17),'value',0);
elseif strcmp(params.component2,'TT')
    set (h2.radio(10),'value',0);
    set (h2.radio(11),'value',0);
    set (h2.radio(12),'value',0);
    set (h2.radio(13),'value',1);
    set (h2.radio(17),'value',0);
elseif strcmp(params.component2,'RZ')
    set (h2.radio(10),'value',0);
    set (h2.radio(11),'value',0);
    set (h2.radio(12),'value',0);
    set (h2.radio(13),'value',0);
    set (h2.radio(17),'value',1);
end
% get(h2.radiobutton(4),'selectedobject')



if strcmp(params.vtaper2,'yes')
    set (h2.vtaper2,'value',1);    
    set (h2.vt_inter2,'Enable','on');
elseif strcmp(params.vtaper2,'no')
    set (h2.vtaper2,'value',0);    
    set (h2.vt_inter2,'Enable','off');
end